<?php
error_reporting(E_ALL ^ E_DEPRECATED);
?>
<?php 
require_once ("dbconnect.php");
if(!isset($_SESSION['username']))
	{
      
 	echo '<!doctype html>
<head>
<meta charset="utf-8" />
<title>登陆失败</title>
</head>
<body>
<div align="center">
<h2>温馨提示：若要进入管理页面<a href="login.html">请点此登此登陆</a></h2>  
<span class="copyright">CopyRight 2014-2015 <a href="https://yanyu-dyh.rhcloud.com/">@虎哥Style</a></span>
</div>
</body>
</html>';
exit();
}?>
<?php
    /*******************************/
    /*  文件名：list.php	       */
    /*  功能：?示留言和分?	   */
    /*******************************/

	include "dbconnect.php";

	//当前?数
	$page = isset($_GET['page'])?intval($_GET['page']):1;

	//????数
	$each_page = 50;

	//??留言?数
	$res = mysql_query("SELECT COUNT(*) FROM guestbook WHERE 1=1");
	$total = mysql_result($res, 0);

	//??数
	$total_page = ceil($total/$each_page);

	//?算真?的?数，使得?数?是落在1〜$total_page之?
	$page = ($page<0)?1:$page;
	$page = ($page>$total_page)?$total_page:$page;

	//根据真?的?数?，?算偏移量
	$offset = ($page-1)*$each_page;
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>留言管理</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
 <div align="center">
<h2>留言管理系统</h2>
<div align="center"><a href="exit.php">登出<a></div>
<br>
 <table width="90%" border="0" cellpadding="4" cellspacing="1">
 <tr>
   <td colspan="2" class="HeaderRow">留言列表
	(<?php echo sprintf(" ",$total, $page, $total_page) ?>)</td>
  </tr>
   <td width="10%" align="center" valign="top" class="InputRow">
	 <b class="redfont">ID昵称</b>
   </td>
   <td width="70%" align="center" valign="top" class="InputRow">
	 <b class="redfont">内容</b>
   </td>
    <td width="12%" align="center" valign="top" class="InputRow">
	 <b class="redfont">留言时间</b>
   </td>
   <td width="8%" align="center" valign="top" class="InputRow">
	 <b class="redfont">操作</b>
   </td>
<?php
	if($total)
	{
		//存在留言??
		$sql = "SELECT * FROM guestbook WHERE 1=1
			  ORDER BY postdtm DESC limit $offset, $each_page";
		$res = mysql_query($sql);
		$i = 0;

		//遍?内容?出
		while($row = mysql_fetch_object($res))
		{
			//循??出双色表格
			$tmp = ($i++)%2;
?>
  <tr>
   <td width="10%" align="center"  valign="top" class="InputRow<?php echo $tmp ?>">
	 <?php echo ($row->name) ?><br>
   </td>
   <td width="70%" valign="top" class="InputRow<?php echo $tmp ?>">
	<!-- 正文内容 -->
	<?php echo $row->comment ?>
	</td>
	 <td width="12%" valign="top" class="InputRow<?php echo $tmp ?>">
	<!-- 正文内容 -->
	<?php echo $row->postdtm ?>
	</td>
	<td width="8%" valign="top" class="InputRow<?php echo $tmp ?>">
	 <div align="center">
	<a href="edit.php?id=<?php echo $row->id ?>">编辑</a>	 |
	<a href="del.php?id=<?php echo $row->id ?>">删除</a>
   </div>
   </td>
  </tr>
<?php } ?>
<?php }else{ ?>
  <tr>
  <td colspan="2" class="SubTitleRow" align="center">
	<b>暂无留言内容!</b>
	</td>
	</tr>
<?php } ?>
  <tr>
  <td colspan="3" align="center">
	<?php
		if($page>1){
			//如果&#39029;数大于1，&#21017;激活&#26174;示“前一&#39029;”的按&#38062;
	?>
	    <input type="button" value=" 前一页"
			onClick="location.href='?page=<?php echo $page-1 ?>'">
	<?php
		}else{
			//&#36825;里非激活&#26174;示“前一&#39029;”的按&#38062;
	?>
	    <input type="button" disabled value=" 前一页 ">
	<?php } ?>

	 &nbsp;

	<?php
		if($page<$total_page){
			//如果&#39029;数大于&#24635;&#39029;数，&#21017;激活&#26174;示“下一&#39029;”的按&#38062;
	?>
		<input type="button" value="下一页 "
			onClick="location.href='?page=<?php echo $page+1 ?>'">
	<?php
		}else{
			//&#36825;里非激活&#26174;示“下一&#39029;”的按&#38062;
	?>
	    <input type="button" disabled value=" 下一页">
	<?php } ?>
 </td>
 </tr>
 
</table>
</div>
<br>
<br>
</body>
</html>
